// pages/classify/classify.js
var httpUtil = require('../../utils/httpUtil.js');
var util = require('../../utils/util.js');
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        goodsList: [],
        text: ""
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var that = this;
        //轮播图
        that.getList();
    },
    //获取列表
    getList: function() {
        var that = this;
        httpUtil.getHttp("/goods_travel/list", {}, function(res) {
            that.setData({
                goodsList: res
            })
        })
    },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  bindChange: function (e) {

    var that = this;
    that.setData({ currentTab: e.detail.current });

  },
  swichNav: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current)         { return false; }
     else {
      that.setData({ currentTab: e.target.dataset.current })
    }
  },
  addShop:function(e){

    var id = e.target.dataset.id;
    var goodsType = e.target.dataset.type;
    var userInfo = util.getKey("userInfo");

    httpUtil.getHttp("/car/add", {id:id,userId:userInfo.id}, function (res) {
     if(res=='0'){
       wx.showToast({
         title: '商品无相关规格',
         icon: 'loading',
         duration: 1000,
         mask: true
       })
     }else{
       wx.showToast({
         title: '添加成功',
         icon: 'success',
         duration: 1000,
         mask: true
       })
     }
  
    })
  },
  showDetail:function(){
    wx:wx.navigateTo({
      url: '../visaInfo/visaInfo',
    })
  },
  getTravel:function(e){
    var id = e.target.dataset.id; 
    var goodsType = e.target.dataset.type;
  
    if (id == undefined) {
      return;
    }

    if (goodsType == undefined) {
      return;
    }
   
    if (goodsType != undefined && goodsType == 4) {
      wx.navigateTo({
        url: '../detail/detail?id=' + id
      })
      return
    }
    if (goodsType != undefined && goodsType == 6) {
      wx.navigateTo({
        url: '../category_chartere/category_chartere' 
      })
      return
    }
    if (goodsType != undefined && goodsType == 0) {
      wx.navigateTo({
        url: '../visaInfo/visaInfo?id=' + id
      })
      return
    }
    wx: wx.navigateTo({
      url: '../proInfo/proInfo?id='+id,
    })
  }, search: function (e) {
    wx.navigateTo({
      url: '../search/search'
    })
  } 
})